/**
* @program: src
*
* @description:
*
* @author: Mr.chen
*
* @create: 2020-11-06 17:44
**/
package user

import (
	"ydd-im/service/api/services/wsservice/account"
	"ydd-im/service/api/services/wsservice/client"
	"ydd-im/service/api/tools/bind"
	"ydd-im/service/api/tools/response"
	"fmt"

	"github.com/gin-gonic/gin"
	"github.com/go-playground/validator/v10"



)

type Controller struct {
}

type inputData struct {
	GroupName string      `json:"groupName" validate:"required"`
	Code      int         `json:"code"`
	Msg       string      `json:"msg"`
	Data      interface{} `json:"data"`
}

func (r *Controller) GetOnlineList(c *gin.Context) {
	var inputData inputData
	s, err := bind.Bind(&inputData, c)
	if err != nil {
		response.ResponseJsonFail(c, response.Response{
			Code:  response.ErrorCode,
			Message: err.Error(),
		})
		return
	}
	// 参数验证
	validate := validator.New()
	// 注册自定义验证
	//_ = validate.RegisterValidation("NameValid", param_verify.NameValid)
	if err = validate.Struct(s); err != nil {
		response.ResponseJsonFail(c, response.Response{
			Code:  response.ErrorCode,
			Message: err.Error(),
		})
		return
	}
	systemId := c.Request.Header.Get("systemId")
	fmt.Println(systemId,inputData.GroupName)
	ret := client.GetOnlineList(&systemId, &inputData.GroupName)
	response.ResponseJsonOk(c, response.Response{
		Code:  response.SuccessCode,
		Message: "success",
		Data: ret,
	})
	return
}
// 获取签名相关的所有用户
func (r *Controller) GetAllUserList(c *gin.Context) {
	// 获取appkey查询的用户信息
	//appkey := c.Request.Header.Get("appkey")
	userInfo, err := account.GetMiddleUserInfo(c)
	if  err != nil {
		response.ResponseJsonFail(c, response.Response{
			Code:    response.ErrorCode,
			Message: err.Error(),
		})
		return
	}
	UserList,err := account.GetAllUserJoinSignList(userInfo.Sid,userInfo.Id)
	if err != nil {
		response.ResponseJsonFail(c, response.Response{
			Code:    response.ErrorCode,
			Message: err.Error(),
		})
		return
	}
	response.ResponseJsonOk(c, response.Response{
		Code:  response.SuccessCode,
		Message: "success",
		Data: UserList,
	})
	return
}

